package com.example.orderfood2.managerOperate;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.Toolbar;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.orderfood2.DatabaseManager.DatabaseManager;
import com.example.orderfood2.MainActivity;
import com.example.orderfood2.R;
import com.example.orderfood2.Repository.ClassInfoRepository;
import com.example.orderfood2.util.DBUtil;
import com.example.orderfood2.util.ToolsUtil;

public class AddClassActivity extends AppCompatActivity {

//    private DBUtil dbUtil;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
//        dbUtil=new DBUtil(this);
        DatabaseManager databaseManager = DatabaseManager.getInstance(this);
        ClassInfoRepository dbUtil = databaseManager.getClassInfoRepository();
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_add_class);
        //获取输入框
        EditText et_class_number=findViewById(R.id.et_class_number);
        EditText et_class_name=findViewById(R.id.et_class_name);
        //按钮添加点击事件
       Button class_add=findViewById(R.id.class_add);
       class_add.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               String classNumber= ToolsUtil.editTextToString(et_class_number);
               String className= ToolsUtil.editTextToString(et_class_name);
               if(className.isEmpty()||classNumber.isEmpty()){
                   Toast.makeText(AddClassActivity.this,"请将表单填写完整",Toast.LENGTH_SHORT).show();
               }else {
                   long result=dbUtil.InsertClass(classNumber,className);
                   if(result!=-1){
                       Toast.makeText(AddClassActivity.this,"新班级添加成功",Toast.LENGTH_SHORT).show();
                       et_class_number.setText("");
                       et_class_name.setText("");
                   }else {
                       Toast.makeText(AddClassActivity.this,"新班级添加失败",Toast.LENGTH_SHORT).show();

                   }
               }

           }
       });
    }
}